package com.thoughtworks.opensource.yui.dd.client.helpers;
/*
   Copyright 2006 C. K. Sidu Ponnappa

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.thoughtworks.opensource.yui.dd.client.triads.constrainedgrid.ConstrainedGridController;
import com.thoughtworks.opensource.yui.dd.client.triads.constrainedgrid.ConstrainedGridView;
import com.thoughtworks.opensource.yui.dd.client.triads.incomingnumbers.IncomingNumbersModel;
import com.thoughtworks.opensource.yui.dd.client.triads.incomingnumbers.IncomingNumbersPanel;
import com.thoughtworks.opensource.yui.dd.client.windowresources.DisplayAreaController;
import com.thoughtworks.opensource.yui.dd.client.windowresources.DisplayAreaViewBase;

/**
 * Created by IntelliJ IDEA.
 * Author: C. K. Sidu Ponnappa
 * Date: Nov 21, 2006
 * Time: 5:11:32 PM
 * ThoughtWorks India Pvt. Ltd.
 */
public class Factory {
    public static Label createLabel(String id, String text, String style) {
        Label label = new Label(text);
        label.addStyleName(style);
        setId(label, id);
        return label;
    }

    private static void setId(Widget widget, String id) {
        DOM.setAttribute(widget.getElement(), "id", id);
    }

    public static ConstrainedGridView createDropAreaFlexTable(String id, String style, DisplayAreaViewBase hostView, DisplayAreaController hostController) {
        ConstrainedGridView grid = new ConstrainedGridView(hostView, new ConstrainedGridController(hostController));
        grid.addStyleName(style);
        setId(grid, id);
        return grid;
    }

    public static FlowPanel createFlowPanel(String id, String style) {
        FlowPanel panel = new FlowPanel();
        panel.addStyleName(style);
        setId(panel, id);
        return panel;
    }

    public static IncomingNumbersPanel createIncomingNumberPanel(String id, String style, IncomingNumbersModel model, DisplayAreaViewBase hostView, DisplayAreaController hostController) {
        IncomingNumbersPanel panel = new IncomingNumbersPanel(hostView, hostController, model);
        panel.addStyleName(style);
        setId(panel, id);
        return panel;
    }
}
